package com.bawei.common.core.domain;

import com.bawei.common.core.constant.Constants;
import lombok.Data;

/**
 * @author 美国五星上将麦克阿瑟
 */
@Data
public class Result<T> {

    private static final long serialVersionUID = 1L;

    /** 成功 */
    public static final int SUCCESS = Constants.SUCCESS;

    /** 失败 */
    public static final int FAIL = Constants.FAIL;

    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> ok()
    {
        return restResult(null, SUCCESS, null);
    }

    public static <T> Result<T> ok(T data)
    {
        return restResult(data, SUCCESS, null);
    }

    public static <T> Result<T> ok(T data, String message)
    {
        return restResult(data, SUCCESS, message);
    }

    public static <T> Result<T> fail()
    {
        return restResult(null, FAIL, null);
    }

    public static <T> Result<T> fail(String message)
    {
        return restResult(null, FAIL, message);
    }

    public static <T> Result<T> fail(T data)
    {
        return restResult(data, FAIL, null);
    }

    public static <T> Result<T> fail(T data, String message)
    {
        return restResult(data, FAIL, message);
    }

    public static <T> Result<T> fail(int code, String message)
    {
        return restResult(null, code, message);
    }

    private static <T> Result<T> restResult(T data, int code, String message)
    {
        Result<T> apiResesult = new Result<>();
        apiResesult.setCode(code);
        apiResesult.setData(data);
        apiResesult.setMessage(message);
        return apiResesult;
    }











}
